<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增学习视频')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-videoInfo-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">分类：</label>
            <div class="col-sm-8">
                <select name="classifyId" th:with="item=${@dict.selectVideoClassifyList()}" class="form-control">
                    <option value="">所有</option>
                    <option th:each="dict : ${item}" th:text="${dict.classifyName}"
                            th:value="${dict.classifyId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">标题：</label>
            <div class="col-sm-8">
                <input name="title" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">视频：</label>
            <div class="col-sm-8">
                <input class="file" id="videoFile" type="file" data-min-file-count="1"
                       data-theme="fas" accept=".mp4,.avi,.mov">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                    <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}"
                           th:checked="${dict.default}">
                    <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input name="remarks" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "web/videoInfo"
    $("#form-videoInfo-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var formData = new FormData($("#form-videoInfo-add")[0]);
            if ($('#videoFile')[0].files[0] != null) {
                formData.append('videoFile', $('#videoFile')[0].files[0]);
            } else {
                $.modal.alertError("未上传视频")
                return false;
            }
            $.ajax({
                url: prefix + "/add",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function (result) {
                    $.operate.successCallback(result);
                }
            });
        }
    }
    $("#videoFile").fileinput({
        uploadAsync: false,//默认异步上传
        showUpload: false,//是否显示上传按钮
        dropZoneEnabled: false,//是否显示拖拽区域，默认不写为true，但是会占用很大区域
        allowedFileExtensions: ["mp4", "avi", "mov"],
    })
</script>
</body>
</html>